from typing import Dict, Any

class BaseModel:
    def to_dict(self) -> Dict[str, Any]:
        return {k: v for k, v in self.__dict__.items() if not k.startswith('_')}

    @classmethod
    def from_dict(cls, data: Dict[str, Any]):
        instance = cls()
        for k, v in data.items():
            if hasattr(cls, k):
                setattr(instance, k, v)
        return instance